<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateGroupOrdersTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('group_orders', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('用户id');
            $table->unsignedBigInteger('session_id')->comment('场次ID');
            $table->unsignedBigInteger('product_id')->comment('拼单产品id');
            $table->string('order_no')->unique()->comment('订单编号');
            $table->decimal('amount', 10, 2)->comment('价格');
            $table->decimal('gold_amount', 10, 2)->comment('KC通证价格');
            $table->integer('number')->default(0)->comment('数量');
            $table->boolean('is_winner')->default(false)->comment('是否中单');
            $table->boolean('is_card')->default(false)->comment('是否使用垫付卡');
            $table->unsignedBigInteger('card_id')->nullable()->comment('垫付卡ID');
            $table->boolean('is_forced')->nullable()->default(false)->comment('强制中单');
            $table->integer('user_order_count')->default(0)->comment('用户累计拼单数');
            $table->timestamps();
        });
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `group_orders` comment '拼单记录表'");
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('group_orders');
    }
}
